import os
import re
import matplotlib.pyplot as plt # type: ignore

import csv
def ismatchpath(fn):
    pattren1 = re.compile('202[0-9]{5}.csv')
    if pattren1.fullmatch(fn) != None:
        return True
    else:
        return False


dn = r'c:\users\yt\documents'
fnl = os.listdir(dn)

yss = [[] for i in range(20)]
yss2 = [[] for i in range(20)]
yss3 = [[] for i in range(2)]
yss4 = [[] for i in range(2)]
print(len(yss))
fns = []
for f in fnl:
    if ismatchpath(f):
        with open(os.path.join(dn, f), encoding='utf-8') as csvfile:
            csvrd = csv.reader(csvfile)
            rows = list(csvrd)
            #print(rows.__len__())
            fns.append(f.split('.')[0])
            for r in range(20):
                yss[r].append(float(rows[r][9]))
                yss2[r].append(float(rows[r][10]))
            yss3[0].append(float(rows[0][12]))
            yss3[1].append(float(rows[1][12]))
            yss4[0].append(float(rows[0][13]))
            yss4[1].append(float(rows[1][13]))

plt.rcParams['font.sans-serif'] = ['SimHei']
fig, ax = plt.subplots(4,1)
#ax[0].set(xlim=[0, 20], ylim=[0, 1], title='An Example Axes', ylabel='Y-Axis', xlabel='X-Axis')
for i in [0,5,9]:
    ax[0].plot(yss[i], label='g{}'.format(i), marker='o')
ax[0].axhline(0.5,label='5', linestyle='--')
ax[0].legend(loc=3)
ax[0].set_xticks(range(len(fns)))
ax[0].set_xticklabels(fns)
ax[0].set_title('5日最大涨幅大于某值的概率')

for i in [0,5,9]:
    ax[1].plot(yss2[i], label='g{}'.format(i), marker='o')
ax[1].axhline(0.5,label='5', linestyle='--')
ax[1].legend(loc=3)
ax[1].set_xticks(range(len(fns)))
ax[1].set_xticklabels(fns)
ax[1].set_title('4日开盘价最大涨幅大于某值的概率')

ax[2].plot(yss3[0], label='ztg5', marker='o')
ax[2].plot(yss3[1], label='fztg5', marker='o')
ax[2].axhline(0.5,label='5', linestyle='--')
ax[2].legend(loc=3)
ax[2].set_xticks(range(len(fns)))
ax[2].set_xticklabels(fns)
ax[2].set_title('涨停中5日最大涨幅大于某值的概率')

ax[3].plot(yss4[0], label='zt4g5', marker='o')
ax[3].plot(yss4[1], label='fzt4g5', marker='o')
ax[3].axhline(0.5,label='5', linestyle='--')
ax[3].legend(loc=3)
ax[3].set_xticks(range(len(fns)))
ax[3].set_xticklabels(fns)
ax[3].set_title('涨停中4日开盘价最大涨幅大于某值的概率')
fig.tight_layout()
plt.show()
